<?php
namespace app\agenttest\controller;

use app\common\model\DeviceMicro;
use app\common\model\User;
use app\common\model\Agent;
use think\Controller;
use think\Request;
use think\Session;


class Mach extends AgenttestBase
{



    public function device_micro_view()
    {

        if (request()->isAjax()) {
            $map['mid'] = request()->post('mid');
            $list = DeviceMicro::where($map)->select();
            return json($list);
        }

    }

    public function device_micro_md_pass()
    {
        if (request()->isAjax()) {
            $map['id'] = request()->post('id');
            $data['tk_pass'] = MD5(request()->post('tk_pass'));
            $DeviceMirco = new DeviceMicro();
            $sa = $DeviceMirco->save($data, $map);
            if ($sa) {
                $arr = array('code' => 0, 'message' => "退款密码修改成功");
            } else {
                $arr = array('code' => 1, 'message' => "退款密码修改失败");
            }
            return json($arr);
        }
    }

    public function device_mirco_jb()
    {
        if (request()->isAjax()) {
            $map['id'] = request()->post('id');
            $data['device_code'] = null;
            $data['status'] = 0;
            $DeviceMirco = new DeviceMicro();
            $sa = $DeviceMirco->save($data, $map);
            if ($sa) {
                $arr = array('code' => 0, 'message' => "解绑设备成功");
            } else {
                $arr = array('code' => 1, 'message' => "解绑设备失败");
            }
            return json($arr);
        }

    }
    public function del_device_mirco(){
        if (request()->isAjax()) {
            $data['mid'] = array('in',$this->get_mer_mid());
            $data['id']=request()->post('id');
            $del=DeviceMicro::where($data)->delete();
            if ($del) {
                $arr = array('code' => 0, 'message' => "删除成功");
            } else {
                $arr = array('code' => 1, 'message' => "删除失败");
            }
            return json($arr);

        }


    }

    public function add_device_micro()
    {
        if (request()->isAjax()) {
            $data['mid'] = request()->post('mid');
            $data['device_name'] = request()->post('device_name');
            $data['code'] = action('common/pub/generate_code');
            $data['is_tk'] = request()->post('is_tk');
            $data['tk_pass'] = MD5(request()->post('tk_pass'));
            $DeviceMirco = new DeviceMicro();
            $save = $DeviceMirco->save($data);
            if ($save) {
                $arr = array('code' => 0, 'message' => '添加成功');
            } else {
                $arr = array('code' => 1, 'message' => '添加失败');
            }
            return json($arr);
        }
    }


}
